package com.ywyt.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.ywyt.util.ConnUtil;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class WorkProvider {
    public static final String QUEUE_NAME="work_queue";
    @Test
    public void publish() throws IOException, TimeoutException {
        //获取连接对象
        Connection connection = ConnUtil.getConnection();
        //获取channel
        Channel channel = connection.createChannel();
        //绑定队列
        /*
        * 1.队列名称
        * 2.是否持久化
        * 3.是否排外
        * 4.是否自动删除
        * */
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        //发布消息
        for (int i=0;i<10;i++){
            String msg = "work"+i;
            channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
        }
        channel.close();
        connection.close();
    }
}
